package com.example.demo;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.init.InitExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class Service3Application {

    private Logger logger = LoggerFactory.getLogger(Service3Application.class);

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(Service3Application.class, args);
        // 连接到控制台，与sentinel控制台通信
        System.setProperty("project.name", context.getEnvironment().getProperty("spring.application.name", "service3"));
        System.setProperty("csp.sentinel.dashboard.server", context.getEnvironment().getProperty("sentinel.dashboard.server", "localhost:8868"));
        System.setProperty("csp.sentinel.api.port", context.getEnvironment().getProperty("sentinel.api.port", "8719"));
        InitExecutor.doInit();
    }

    @GetMapping("/")
    @SentinelResource("index")
    public String index() {
        logger.info("hello service3.");
        return "hello service3.";
    }

}
